// import com.alibaba.druid.sql.ast.SQLCommentHint;
// import com.alibaba.druid.sql.ast.SQLStatement;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLLoopStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"

SQLLoopStatement::SQLLoopStatement()
{
  statements = std::make_shared<std::list<SQLStatement_ptr>>();
}
// @Override
void SQLLoopStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLLoopStatement)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLStatement, SQLObject>(statements);
    acceptChild(visitor, tmp1);
  }
  visitor->endVisit(SharedObject(SQLLoopStatement));
}

SQLStatement_list_ptr SQLLoopStatement::getStatements()
{
  return statements;
}

string_ptr SQLLoopStatement::getLabelName()
{
  return labelName;
}

void SQLLoopStatement::setLabelName(string_ptr labelName)
{
  this->labelName = labelName;
}

void SQLLoopStatement::addStatement(SQLStatement_ptr stmt)
{
  if (stmt != nullptr)
  {
    stmt->setParent(SharedObject(SQLLoopStatement));
  }
  statements->push_back(stmt);
}

// @Override
SQLStatement_list_ptr SQLLoopStatement::getChildren()
{
  return statements;
}

// @Override
SQLObject_ptr SQLLoopStatement::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLLoopStatement>(new SQLLoopStatement());
  std::shared_ptr<SQLLoopStatement> x = std::dynamic_pointer_cast<SQLLoopStatement>(clone_tmp);
  // SQLLoopStatement x = new SQLLoopStatement();

  x->setLabelName(this->labelName);

  x->setAfterSemi(this->afterSemi);

  x->setDbType(this->dbType);

  for (SQLStatement_ptr item : *statements)
  {
    SQLStatement_ptr item2 = std::dynamic_pointer_cast<SQLStatement>(item->clone());
    item2->setParent(x);
    x->statements->push_back(item2);
  }

  if (this->headHints != nullptr)
  {
    SQLCommentHint_list_ptr headHintsClone = std::make_shared<std::list<SQLCommentHint_ptr>>();
    for (SQLCommentHint_ptr hint : *headHints)
    {
      SQLCommentHint_ptr h2 = std::dynamic_pointer_cast<SQLCommentHint>(hint->clone());
      h2->SQLObjectImpl::setParent(x);
      headHintsClone->push_back(h2);
    }
    x->setHeadHints(headHintsClone);
  }

  return x;
}
